import { createRouter, createWebHistory } from 'vue-router'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  // 控制滚动位置
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition
    } else {
      return { top: 0 }
    }
  },
  routes: [
    {
      path: '/',
      name: "layout",
      component: () => import('@/views/Layout.vue'),
      children: [
        {
          path: '/',
          name: '首页',
          component: () => import('@/views/Home/Home.vue'),
        },
        {
          path: '/board/:pBoardId',
          name: "父板块",
          component: () => import('@/views/Article/ArticleList.vue'),
        },
        {
          path: '/board/:pBoardId/:boardId/',
          name: "子板块",
          component: () => import('@/views/Article/ArticleList.vue'),
        },
        {
          path: '/user/:userId',
          name: "用户信息",
          component: () => import('@/views/UserCenter/UserInfo.vue'),
        },
        {
          path: '/post/:articleId',
          name: "文章详情",
          component: () => import('@/views/Article/ArticleDetail.vue'),
        },
        {
          path: '/newPost',
          name: "发布文章",
          component: () => import('@/views/Article/EditPost.vue'),
        },
        {
          path: '/editPost/:articleId',
          name: "编辑文章",
          component: () => import('@/views/Article/EditPost.vue'),
        },
        {
          path: '/user/message/:type',
          name: "消息",
          component: () => import('@/views/UserCenter/UserMessage.vue'),
        },
        {
          path: '/search',
          name: "搜索结果",
          component: () => import('@/views/Article/ArticleList.vue'),
        }
      ]
    },
    {
      path: "/:pathMatch(.*)*",
      name: "404",
      component: () => import("@/views/404/404.vue")
    }
  ],
})

export default router
